{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# OOPs \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "lst = [1,2,3,4,5]\n",
    "\n",
    "dit = {\"key1\":234,\"key2\":3553}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'key1': 234, 'key2': 3553}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dit"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "OOP IS USED FOR making repeatable and organised code when we have to develop program keeping real world objects in mind,\n",
    "\n",
    "for example u are a car company owner, u want to maintian a full list of cars, \n",
    "\n",
    "then u will create an object known as Car and then give it properties\n",
    "\n",
    "based upon the properties, we can code our whole usecase\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "# We need to make a car object in python program \n",
    "\n",
    "\n",
    "# Car Sr. No. - 02\n",
    "# Car Color - black\n",
    "# Car Fuel - cng\n",
    "# Car Passenger - 4+1\n",
    "# Car is sold in - 2015\n",
    "# Car type - suv\n",
    "# Car model - 2013\n",
    "\n",
    "\n",
    "class car():\n",
    "    '''\n",
    "    THis is a Car Object which is used for storing the 3 basic values of car\n",
    "    you need to pass car_sr_no, car_color, car_fuel when initilization it\n",
    "    '''\n",
    "    def __init__(self, car_sr_no=\"blank\", car_color=\"blank\", car_fuel=\"blank\"):\n",
    "        self.car_sr_no = car_sr_no\n",
    "        self.car_color = car_color\n",
    "        self.car_fuel = car_fuel\n",
    "        \n",
    "    def some_method_to_print(self):\n",
    "        print(self.car_sr_no)\n",
    "        print(self.car_color)\n",
    "        print(self.car_fuel)\n",
    "    def set_car_sr_no(self,car_sr_no):\n",
    "        self.car_sr_no = car_sr_no\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "wagaonR = car(\"wagon1\",\"Navy Blue\",\"Petrol\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Navy Blue'"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wagaonR.car_color"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Petrol'"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wagaonR.car_fuel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'wagon1'"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wagaonR.car_sr_no"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wagon1\n",
      "Navy Blue\n",
      "Petrol\n"
     ]
    }
   ],
   "source": [
    "wagaonR.some_method_to_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "swift = car(\"swift1\",\"White\",\"Petrol\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "swift1\n",
      "White\n",
      "Petrol\n"
     ]
    }
   ],
   "source": [
    "swift.some_method_to_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "skodarapid = car()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "blank\n",
      "blank\n",
      "blank\n"
     ]
    }
   ],
   "source": [
    "skodarapid.some_method_to_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'car' object has no attribute 'set_car_sr_no'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-73-51cdc9ccd16d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mrapid\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_car_sr_no\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Rapid123\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m: 'car' object has no attribute 'set_car_sr_no'"
     ]
    }
   ],
   "source": [
    "rapid.set_car_sr_no(\"Rapid123\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Rapid123\n",
      "blank\n",
      "blank\n"
     ]
    }
   ],
   "source": [
    "rapid.some_method_to_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "jeepcompass = car()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "blank\n",
      "blank\n",
      "blank\n"
     ]
    }
   ],
   "source": [
    "jeepcompass.some_method_to_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "jeepcompass.set_car_sr_no(\"Jeep_chn_01\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jeep_chn_01'"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jeepcompass.car_sr_no"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define a class for circle and develop methods, like perimeter, area\n",
    "\n",
    "class circle():\n",
    "    pi = 3.14\n",
    "    \n",
    "    def __init__(self, radius):\n",
    "        self.radius = radius\n",
    "    \n",
    "    sumit = lambda self : print(self.radius)\n",
    "    \n",
    "    def getArea(self):\n",
    "        return circle.pi * self.radius * self.radius\n",
    "    \n",
    "    def getCircumference(self):\n",
    "        return 2 * circle.pi * self.radius"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "circle1 = circle(23)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1661.06"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "circle1.getArea()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "144.44"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "circle1.getCircumference()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "23\n"
     ]
    }
   ],
   "source": [
    "circle1.sumit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Inheritance "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Parent class methods+ attributes can be called inside the child class "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "#parent class\n",
    "class pen():\n",
    "    def __init__ (self,companyName,penType):\n",
    "        self.companyName = companyName \n",
    "        self.penType = penType \n",
    "    def getPenCompany(self):\n",
    "        print(self.companyName)\n",
    "    def getPenType(self):\n",
    "        print(self.penType)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Child Class\n",
    "class uniPen(pen):\n",
    "    def __init__ (self,penType, country, color, srno, price):\n",
    "        self.country = country\n",
    "        self.color = color\n",
    "        self.srno = srno\n",
    "        self.price = price\n",
    "        pen.__init__(self,\"uniPen\",penType)\n",
    "        \n",
    "    def setPenType(self,newPenType):\n",
    "        print(\"We are inside the UniPen class\")\n",
    "        self.penType = newPenType\n",
    "        print(\"Pen Type is - \",self.penType)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "zeroPointOneBlack = uniPen(\"ink\",\"Japan\",\"#212121\",\"sr123\",90)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "uniPen\n"
     ]
    }
   ],
   "source": [
    "zeroPointOneBlack.getPenCompany()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ink\n"
     ]
    }
   ],
   "source": [
    "zeroPointOneBlack.getPenType()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "We are inside the UniPen class\n",
      "Pen Type is -  Gel\n"
     ]
    }
   ],
   "source": [
    "zeroPointOneBlack.setPenType(\"Gel\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gel\n"
     ]
    }
   ],
   "source": [
    "zeroPointOneBlack.getPenType()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Stree Reported = ParentClassProperties + NewChildProperties = inHeritance "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
